#include"yxt.h"
bool *t_flag;

void yxt::read(yxt::youxiangtu<int> &t)
{
	int n;
	int m;
	std::cout << "input n dian" << std::endl;
	std::cin >> n;
	std::cout << "input m bian" << std::endl;
	std::cin >> m;
	t_flag = new bool[n];
	for (int i = 0;i < n;i++)
	{
		yxt::nodex<int> buffer(i);
		t.lie.push_back(buffer);
	}
	for (int i = 0;i<n;i++)
	{
		for (int j = 0;j<n;j++)
		{
			int s = 0;
			t.lie[i].out.push_back(s);
			t.lie[i].in.push_back(s);
		}
	}
	for (int i = 0;i < m;i++)
	{
		int x, y;
		std::cin >> x;
		std::cin >> y;
		t.lie[x].out[y] = 1;
		t.lie[y].in[x] = 1;
	}
}
int yxt::if_tuopu_over(yxt::youxiangtu<int> &t)
{
	for (int i = 0;i <(int)t.lie.size();i++)
		if ((t.lie[i].Get_in_num() == 0) && (t_flag[i] != true))
			return i;
	return -1;
}
bool yxt::tuopu(yxt::youxiangtu<int> &t, std::vector<int> &ans)
{
	int k = -1;
	k = if_tuopu_over(t);
	while (k != -1)
	{
		for (int i = 0;i < (int)t.lie[k].out.size();i++)
		{
			if (t.lie[k].out[i]>0)
			{
				t.lie[i].in[k] = 0;
			}
		}
		t_flag[k] = true;
		ans.push_back(k);
		if (ans.size() > t.lie.size())
			return false;
		k = if_tuopu_over(t);
	}
	if ((int)ans.size()>0)
		return true;
	else
		return false;
}
void yxt::spfa(yxt::youxiangtu<int> &t,int start,std::vector<int>&dis)
{
	bool *flag;
	flag=new bool[t.lie.size()];
	t.s_init();
	for(int i=0;i<t.lie.size();i++)
	{
		flag[i]=false;
		dis.push_back(t.lie[start].out[i]);
	}
	queue<yxt::nodex> q;
	q.push(t.lie[start]);
	flag[start]=true;
	while(q.empty())
	{
		yxt::nodex buf=q.front();
		q.pop();
		flag[buf.id]=false;
		for(int i=0;i<buf.out.size();i++)
		{
			if((flag[i]!=true)&&(dis[i]>dis[buf.id]+t.lie[buf.id].out[i]))
			{
				dis[i]=dis[buf.id]+t.lie[buf.id].out[i];
				flag[i]=true;
				q.push(t.lie[i]);
			}
		}
	}
	delete[] flag;
}
//for tuopu test 
/*
4 3
0 1
1 2
2 3
*/
/*
4 4
0 1
1 2
2 3
3 0
*/
